package com.ruoyi.nlp.utils;

import com.ruoyi.common.config.DbConfig;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;


/**
 * 数据库连接池
 * 
 * @author anhuifeng
 * 
 */
public class BaseDAO {

	public Connection con = null;
	public PreparedStatement ps = null;
	public ResultSet rs = null;

	static {
		try {
			Class.forName(DbConfig.JDBC_DRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	public void getConnection() {
		if (con == null)
			try {
				con = DriverManager.getConnection(DbConfig.JDBC_URL, DbConfig.JDBC_USERNAME, DbConfig.JDBC_PASSWORD);
			} catch (SQLException e) {
				e.printStackTrace();
			}
	}

	public void close() {
		if (rs != null)
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		if (ps != null)
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		if (con != null)
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		rs = null;
		ps = null;
		con = null;
	}

}
